package android.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 * @hide
 */
public class PeachLog{
	private static final String LOGTAG="PEACHLOG";
	
	public static void track(String category, String behavior,Map<String, String> parms) {
		StringBuilder sb = new StringBuilder();
		sb.append(System.currentTimeMillis() + "").append("|").append(category).append("|");
		if(behavior!=null){
			sb.append(behavior);
		}
		sb.append("|");
		if(parms!=null){
			Set<Entry<String, String>> tt = parms.entrySet();
			boolean first = true;
			for(Entry<String, String> t:tt){
				if(!first){
					sb.append(",");
				}
				else{
					first = false;
				}
				sb.append(t.getKey()+"="+t.getValue());
			}
		}
		StackTraceElement[] st = null;
		Exception e = new RuntimeException();
		try{
			throw e;
		}
		catch(Exception ee){
			st = ee.getStackTrace();
		}
		sb.append("|");
		if(st!=null){
			if(st.length>1){
				for(int i=1;i<st.length;++i){
					sb.append(st[i].toString()+",");
				}
			}
		}
		
		Log.i(LOGTAG, sb.toString());
	}
};